// 初始化表格数据
export default function initTreeArray (data, isExpand, parent = null, level = null) {
  let arr = []
  /**
   * data, isExpand 两个必传
   *  data: 表格原始数据
   *  isExpand: 设置是否展开,默认为false
   * _level: 记录当前的层级
   */
  data.forEach((scope) => {
    if (scope._isExpand === undefined || scope._isExpand === null) {
      scope._isExpand = isExpand
    }
    let _level = 1
    if (level !== undefined && level !== null) {
      _level = level + 1
    }
    scope._level = _level

    // 判断是否有父级
    if (parent) {
      scope.parent = parent
    }

    arr.push(scope)

    if (scope.childList && scope.childList.length > 0) {
      const items = initTreeArray(scope.childList, isExpand, scope, _level)
      arr = arr.concat(items)
    }
  })
  return arr
}
